/***
    Amrita ITEWS - Copyright (C) 2009 Amrita Vishwa Vidyapeetham, Amritapuri.
                                       (http://www.amrita.edu)
    ***************************************************************************
    This file is part of the Amrita ITEWS distribution.
    Amrita ITEWS is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License (version 2) as published
    by the Free Software Foundation AND MODIFIED BY the Amrita ITEWS exception.
    ***NOTE*** The exception to the GPL is included to allow you to distribute
    a combined work that includes Amrita ITEWS without being obliged to provide
    the source code for proprietary components outside of the Amrita ITEWS
    software. Amrita ITEWS is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
    Public License for more details. You should have received a copy of the GNU
    General Public License and the Amrita ITEWS license exception along with
    Amrita ITEWS if not then it can be viewed here:
    http://itews.amrita.ac.in/license.html.


    Documentation, latest information, license and contact details are at:
    http://itews.amrita.ac.in/


    Amrita ITEWS source code can be found at:
    http://code.google.com/p/itews


    The initial code-base of Amrita ITEWS was developed by Amrita Vishwa
    Vidyapeetham as part of the project titled,"Intelligent & Interactive
    Telematics using Emerging Wireless Technologies for Transport Systems
    (ITEWS)" sponsored by Technology Information Forecasting and Assessment
    Council (TIFAC), India.
***/
/*! \file eventq.h
    \brief Event Queue Header File.
*/

#ifndef EVENTQ_H_
#define EVENTQ_H_

#include <event.h>
#include <eventq_errno.h>
#include <errno.h>

/*! \brief Maximu Event Queue Entries.*/
#define EVENTQ_MAX_ENTRIES      100

/*! \brief Entry Open Flag.*/
#define EVENTQ_ENTRY_OPEN       1

/*! \brief Entry Closed Flag.*/
#define EVENTQ_ENTRY_CLOSED     0


/*! \brief EventQ Context Structure.*/
typedef struct
{
    /*! \brief Context Specific Data.*/
    uint32 ctx_data;
}eventq_ctx_t;

/*! \brief EventQ Operations Structure.*/
typedef struct
{
    /*! \brief EventQ Open Function.*/
    STATUS (*open)     ( eventq_ctx_t *, const char *eventq_name );

    /*! \brief EventQ Close Function.*/
    STATUS (*close)    ( eventq_ctx_t * );

    /*! \brief EventQ Synchronous Get Function.*/
    STATUS (*sync_get) ( eventq_ctx_t *, event_t * );

    /*! \brief EventQ Synchronous Put Function.*/
    STATUS (*sync_put) ( eventq_ctx_t *, event_t *, HRESULT *res );

    /*! \brief EventQ Asynchronous Get Function.*/
    STATUS (*async_get)( eventq_ctx_t *, event_t * );

    /*! \brief EventQ Asynchronous Put Function.*/
    STATUS (*async_put)( eventq_ctx_t *, event_t *, HRESULT *res );
}eventq_ops_t;

/*! \brief Event Queue Entry Structure.*/
typedef struct
{
    /*! \brief EventQ Name.*/
    const char      *eventq_name;

    /*! \brief EventQ Context Structure.*/
    eventq_ctx_t        ctx;

    /*! \brief EventQ Operations Structure Pointer.*/
    eventq_ops_t        *ops;

    /*! \brief EventQ Open Status Flag.*/
    int8            is_open;

    /*! \brief EventQ Opener Name.*/
    const char      *opener_name;
}eventq_entry_t;


/*APIs*/
STATUS eventq_subsys_init   ( );
STATUS eventq_register      ( const char *eventq_name, eventq_ops_t *ops, int32 max_openers );
STATUS eventq_open          ( const char * eventq_name, const char *opener_name, HEVENTQ *h );
STATUS eventq_sync_put      ( HEVENTQ, event_t * );
STATUS eventq_async_put     ( HEVENTQ, event_t * );
STATUS eventq_sync_get      ( HEVENTQ, event_t * );
STATUS eventq_async_get     ( HEVENTQ, event_t * );
STATUS eventq_close         ( HEVENTQ );
STATUS eventq_subsys_cleanup( );

#endif /*EVENTQ_H_*/
